home *** CD-ROM | disk | FTP | other *** search
- Path: news.mira.net.au!news
- From: davidw@werple.net.au (David White)
- Newsgroups: comp.lang.c++
- Subject: Re: class self destuction???
- Date: 21 Feb 1996 19:48:10 +1100
- Organization: Werple Internet, Melbourne
- Message-ID: <4gem8a$4g7@werple.net.au>
- References: <1996Feb20.152904.13555@alw.nih.gov>
- NNTP-Posting-Host: werple.mira.net.au
-
- Dean Fuqua <dfuqua@raleigh.ibm.com> writes:
-
- >I was wondering what the *correct* method of class suicide is.
- >For example, while in a member function, a class realizes that
- >it is no longer wanted in little computing world and that it should
- >kill itself.
-
- >Should it call it own destuctor and that's that or should it do delete(this).
- >The delete method seems a bit dangerous to me.
-
- Calling its own destructor will kill it, but will not release its memory
- if allocated on the free store (its 'body' remains, polluting the
- program). But if it is a stack-allocated object, it will be killed twice,
- the second time possibly taking the program with it, depending on what the
- destructor does. So calling the destructor isn't an option in either case,
- except in some special situations when it can be resurrected with a
- placement 'new' afterwards. 'delete' should only be used if it can be
- guaranteed that the object was allocated with 'new'.
-
- David White
- davidw@werple.mira.net.au
-
-